/**
 * 获取四位数字
 * @param {*} lotteryDrawResult 
 * @returns 
 */
export const getFourNumbers = (lotteryDrawResult) => {
    return lotteryDrawResult.split(' ').slice(0, 4).map(item => Number(item))
}

/**
 * 获取四位之和
 * @param {*} lotteryDrawResult 
 * @returns 
 */
export const getFourNumbersSum = (lotteryDrawResult) => {
    return getFourNumbers(lotteryDrawResult).reduce((previousValue, currentValue) => Number(previousValue) + Number(currentValue), 0)
}

/**
 * 获取两位之和
 * @param {*} lotteryDrawResult 
 * @param {*} index1 
 * @param {*} index2 
 * @returns 
 */
export const getTwoNumbersSum = (lotteryDrawResult, index1, index2) => {
    const numbers = getFourNumbers(lotteryDrawResult)
    return Number(numbers[index1]) + Number(numbers[index2])
}

/**
 * 获取中奖状态
 * @param {*} item 
 */
export const getWinningResult = (item) => {

    const { filter } = item

    const result = {
        fourPlaceSumStatus: true,
        sameRepeatStatus: true,
    }

    // 四位和值结果
    if (filter.fourPlaceSumRange && filter.fourPlaceSumRange.length > 0) {
        const sum = getFourNumbersSum(item.lotteryDrawResult)
        if (sum < filter.fourPlaceSumRange[0] || sum > filter.fourPlaceSumRange[1]) {
            result.fourPlaceSumStatus = false
        }
    }

    // 同位重复结果
    if (filter.repeatIndexArray && filter.repeatIndexArray.length > 0) {
        result.sameRepeatStatus = false
    }

    return result
}
